package com.acwing.partition2;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;

/**
 * @author `RKC`
 * @date 2021/12/29 14:39
 */
public class AC179八数码 {

    private static final int[][] dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    private static final String[] operator = {"u", "r", "d", "l"};

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 9; i++) sb.append(s[i]);
        //统计逆序对的数量，如果逆序对数量是奇数说明无解
        String start = sb.toString(), end = "12345678x";
        int seq = 0;
        for (int i = 0; i < start.length(); i++) {
            if (start.charAt(i) == 'x') continue;
            for (int j = i + 1; j < start.length(); j++) {
                if (start.charAt(j) == 'x') continue;
                if (start.charAt(j) > start.charAt(i)) seq++;
            }
        }
        if ((seq & 1) == 1) writer.write("unsolvable\n");
        else writer.write(aStar(start, end) + "\n");
        writer.flush();
    }

    private static String aStar(String start, String end) {
        Map<String, Integer> distMap = new HashMap<>();
        //value[1]经过value[0]操作变成了key状态
        Map<String, String[]> prev = new HashMap<>();
        PriorityQueue<Node> heap = new PriorityQueue<>((o1, o2) -> Integer.compare(o1.val, o2.val));
        distMap.put(start, 0);
        heap.add(new Node(start, eval(start)));
        while (!heap.isEmpty()) {
            Node currNode = heap.poll();
            String curr = currNode.state;
            if (curr.equals(end)) break;
            //找到x的位置
            int x = 0, y = 0, dis = distMap.get(curr);
            for (int i = 0; i < 9; i++) {
                if (curr.charAt(i) == 'x') {
                    x = i / 3;
                    y = i % 3;
                    break;
                }
            }
            for (int i = 0; i < dirs.length; i++) {
                int[] dir = dirs[i];
                int nextX = dir[0] + x, nextY = dir[1] + y;
                if (nextX < 0 || nextX >= 3 || nextY < 0 || nextY >= 3) continue;
                String next = swap(curr, x * 3 + y, nextX * 3 + nextY);
                //如果之前没有扩展过或者扩展过但是之前的距离比较大，就进行更新
                if (!distMap.containsKey(next) || distMap.get(next) > dis + 1) {
                    distMap.put(next, dis + 1);
                    //记录是由哪个状态转移过来的，并将当前新状态加入堆
                    prev.put(next, new String[]{operator[i], curr});
                    heap.add(new Node(next, dis + 1 + eval(next)));
                }
            }
        }
        StringBuilder answer = new StringBuilder();
        while (!end.equals(start)) {
            String[] tuple = prev.get(end);
            answer.append(tuple[0]);
            end = tuple[1];
        }
        return answer.reverse().toString();
    }

    private static int eval(String state) {
        //估价函数，这里是非X和真实最终状态的曼哈顿距离
        int res = 0;
        for (int i = 0; i < state.length(); i++) {
            if (state.charAt(i) != 'x') {
                int real = state.charAt(i) - '1';
                res += Math.abs(i / 3 - real / 3) + Math.abs(i % 3 - real % 3);
            }
        }
        return res;
    }

    private static String swap(String s, int x, int y) {
        char[] arr = s.toCharArray();
        char t = arr[x];
        arr[x] = arr[y];
        arr[y] = t;
        return new String(arr);
    }

    private static class Node {
        private String state;
        private int val;

        public Node(String state, int val) {
            this.state = state;
            this.val = val;
        }
    }
}
